﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using SSPharma.Utility.Filter;

namespace SSPharma.Utility.Filter
{
    public abstract class FilterBase
    {
        public event EventHandler FilteringChanged;

        public abstract bool IsMatch(object target);

        public static FilterBase CreateCustomFilter(PropertyInfo pi)
        {
            try
            {
                Type filterType = typeof(CustomFilter<>).MakeGenericType(pi.PropertyType);
                return (FilterBase)Activator.CreateInstance(filterType, pi);
            }
            catch
            {
                return null;
            }
        }

        public void OnFilterChanged()
        {
            if (FilteringChanged != null)
            {
                EventHandler handler = FilteringChanged;
                handler(this, new EventArgs());
            }
        }
    }
}
